﻿@page "/Data"

<Card>
    <ChildContent>
        <div class="card">
            <div class="chart">
                <BcChart @ref="@bcChart" Height="400" Width="600" Data="DemoData.Githubs" CategoryField="x=>x.Year.ToString()" DataFilter="DataFilter">
                    <BcTitle Title="数据筛选" TData="Github"></BcTitle>
                    <BcColumnSeries TData="Github" ValueFunc="x=>x.Sum(y=>y.View)" GroupName="View"></BcColumnSeries>
                    <BcColumnSeries TData="Github" ValueFunc="x=>x.Sum(y=>y.Start)" GroupName="Start"></BcColumnSeries>
                    <BcLineSeries TData="Github" ValueFunc="x=>x.Sum(y=>y.Fork)" GroupName="Fork"></BcLineSeries>
                </BcChart>
            </div>
            <div class="prop">
                <Divider Text="起始年份" Orientation="left"></Divider>
                <InputNumber @bind-Value="@startYear"></InputNumber>

                <Divider></Divider>
                <Button Type="primary" OnClick="OnClick">应用</Button>
                <Button Type="primary" OnClick="OnRandomData">随机数据并应用</Button>
            </div>
        </div>
    </ChildContent>
</Card>

<ApiTable Component="typeof(BcChart<object>)"></ApiTable>

@code{
    BcChart<Github> bcChart;

    int? startYear;

    bool DataFilter(Github data)
    {
        if (startYear.HasValue == false) return true;
        return data.Year >= startYear.Value;
    }

    public void OnClick()
    {
        bcChart.Refresh();
    }

    public void OnRandomData()
    {
        Random random = new Random();
        foreach (var item in DemoData.Githubs)
        {
            item.View = random.Next(2000);
            item.Start = random.Next(2000);
            item.Fork = random.Next(2000);
        }
        bcChart.Refresh();
    }

}
